import 'package:flutter/material.dart';
import 'dart:io';
import 'dart:convert';
import 'package:startup_hw/widget/news.dart';

class StaticPage extends  StatefulWidget{
  @override
  createState() => new ListState();
}

class ListState extends State<StaticPage>{
  @override
  List<Map <String,String>> newTitle=[];
  _get() async {
    var responseBody;
    var url='http://10.0.0.100:8000/yt/getapp/';
    var httpClient = new HttpClient();
    var request = await httpClient.getUrl(Uri.parse(url));
    var response = await request.close();
    if (response.statusCode == 200) {
      responseBody = await response.transform(utf8.decoder).join();
      responseBody=json.decode(responseBody);
    }else{
      print("error");
    }
    await responseBody['msg'].map((Map item){
      newTitle.add(item);
    }).toList();
  }
  Widget build(BuildContext context) {
    _get();
    return new ListView(
      children: newTitle.map((Map  item){
        return  new News(item['title'],item['imglinks']);//News接收2个参数（标题和图片url）
      }).toList(),
    );
  }
}
